/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.cotec.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 *
 * @author magalhaes
 */
@Entity
@Table(name = "instituicao")
@NamedQueries({@NamedQuery(name = "Instituicao.findAll", query = "SELECT i FROM Instituicao i"), 
			   @NamedQuery(name = "Instituicao.findById", query = "SELECT i FROM Instituicao i WHERE i.id = :id"), 
			   @NamedQuery(name = "Instituicao.findByNome", query = "SELECT i FROM Instituicao i WHERE i.nome = :nome"), 
			   @NamedQuery(name = "Instituicao.findByUnidade", query = "SELECT i FROM Instituicao i WHERE i.unidade = :unidade"), 
			   @NamedQuery(name = "Instituicao.findByDescricao", query = "SELECT i FROM Instituicao i WHERE i.descricao = :descricao")})
public class Instituicao implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    @Column(name = "nome", length=45)
    private String nome;
    @Column(name = "unidade", length=5)
    private String unidade;
    @Column(name = "email", length=45, nullable=true)
    private String email;
    @Column(name = "descricao", length=45, nullable=true)
    private String descricao;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "instituicao")
    private List<Setor> setorList;
    @OneToOne(cascade = CascadeType.ALL, targetEntity = Logradouro.class, mappedBy = "instituicao", fetch = FetchType.EAGER)
    private Logradouro logradouro;

    public Instituicao() {
    	this.setLogradouro(new Logradouro());
    	this.setSetorList(new ArrayList<Setor>());
    }

    public Instituicao(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getUnidade() {
        return unidade;
    }

    public void setUnidade(String unidade) {
        this.unidade = unidade;
    }

    public String getDescricao() {
        return descricao;
    }

    public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public void setDescricao(String descricao) {
        this.descricao = descricao;
    }

    public List<Setor> getSetorList() {
        return setorList;
    }

    public void setSetorList(List<Setor> setorList) {
        this.setorList = setorList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    public Logradouro getLogradouro() {
		return logradouro;
	}

	public void setLogradouro(Logradouro logradouro) {
		this.logradouro = logradouro;
	}

	@Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Instituicao)) {
            return false;
        }
        Instituicao other = (Instituicao) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return this.nome;
    }

}
